<template>
  <div class="user">
    <!-- 表格 -->
    <el-table
      :data="records"
      border
      style="width: 100%; margin: 0 auto; margin-top: 100px"
    >
      <el-table-column width="75"> </el-table-column>
      <el-table-column prop="id" label="用户id" width="300"></el-table-column>
      <el-table-column prop="createTime" label="创建时间" width="300">
      </el-table-column>
      <el-table-column prop="job" label="职位" width="300"> </el-table-column>
      <el-table-column prop="userName" label="用户名称" width="300">
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="now"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="pagination"
    >
    </el-pagination>
  </div>
</template>

<script>
import { GetUser } from "../api";
export default {
  name: "User",
  data() {
    return {
      now: 1, //页数
      size: 10, //每页数据量
      total: 1, //总数据个数
      records: [],
      currentPage1: 5,
      currentPage2: 5,
      currentPage3: 5,
      currentPage4: 4,
    };
  },
  created() {
    this.getuser();
  },
  methods: {
    // 获取数据
    getuser() {
      GetUser({ now: this.now, size: this.size }).then((res) => {
        if (res.status == 200) {
          this.$message.success("获取数据成功");
          this.total = res.data.data.total;
          this.records = res.data.data.records;
        } else {
          this.$message.error("获取数据失败");
        }
      });
    },

    // 分页
    handleSizeChange(newSize) {
      this.size = newSize;
      this.getuser();
    },

    handleCurrentChange(newPage) {
      this.now = newPage;
      this.getuser();
    },
  },
};
</script>

<style scoped>
.pagination {
  position: absolute;
  left: 60%;
}
</style>